import 'package:flutter/material.dart';

class ButtonrTest extends StatefulWidget {
  ButtonrTest({Key key}) : super(key: key);
  @override
  _ButtonrTestState createState() => _ButtonrTestState();
}

class _ButtonrTestState extends State<ButtonrTest> {
  int currentIndex = 0;
  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        title: Text('ButtonrTest'),
      ),
      floatingActionButton: Container(
        height: 60,
        width: 60,
        padding: EdgeInsets.all(5),
        // color: Colors.white,
        decoration: BoxDecoration(
            color: Colors.white,
            // borderRadius:
            // border: Border.all(color: Color(0xFFFF0000), width: 0.5),
            borderRadius: BorderRadius.circular(30)),
        child: FloatingActionButton(
          child: Icon(
            Icons.add,
            size: 40,
          ),
          onPressed: () {
            setState(() {
              this.currentIndex = 2;
            });
          },
        ),
      ),
      floatingActionButtonLocation: FloatingActionButtonLocation.centerDocked,
      body: Center(
          child: Column(
        children: [
          Container(
            height: 60,
            width: 300,
            child: RaisedButton(
              onPressed: () {},
              child: Text(
                '按钮1',
                style: TextStyle(color: Colors.white),
              ),
              color: Colors.black45,
            ),
          ),
          Expanded(
              child: Column(
            children: [
              Container(
                height: 200,
                child: RaisedButton.icon(
                  onPressed: () {},
                  icon: Icon(Icons.access_alarm),
                  shape: CircleBorder(side: BorderSide(color: Colors.white24)),
                  label: Text(
                    '',
                    style: TextStyle(color: Colors.white),
                  ),
                  color: Colors.black45,
                  splashColor: Colors.red,
                ),
              ),
            ],
          ))
        ],
      )),
      bottomNavigationBar: BottomNav(
          handleTabChange: (index) {
            setState(() {
              this.currentIndex = index;
            });
          },
          currentIndex: this.currentIndex),
    );
  }
}

class BottomNav extends StatelessWidget {
  List tabs = [
    {'title': '首页', 'icon': Icon(Icons.home)},
    {'title': '分页', 'icon': Icon(Icons.category)},
    {'title': '发布', 'icon': Icon(Icons.settings)},
    {'title': '动态', 'icon': Icon(Icons.cake)},
    {'title': '社区', 'icon': Icon(Icons.access_alarm_outlined)},
  ];
  int currentIndex;
  Function handleTabChange;
  BottomNav({this.handleTabChange = null, this.currentIndex: 0});
  @override
  Widget build(BuildContext context) {
    return BottomNavigationBar(
      items: tabs
          .map((e) =>
              BottomNavigationBarItem(icon: e['icon'], title: Text(e['title'])))
          .toList(),
      onTap: handleTabChange,
      type: BottomNavigationBarType.fixed,
      currentIndex: currentIndex,
    );
  }
}
